using System;
using System.Collections;
using System.Text;
using System.IO;

namespace Patchy
{
    public class GroupHolder
    {
        private SortedList mGroups;
        private SortedList mAliasTable;

        public GroupHolder(SortedList groups)
        {
            mGroups = groups;
        }

        public bool IsEmpty()
        {
            return mGroups == null || mGroups.Count == 0;
        }

        public void Process()
        {
            foreach (MyGroup group in mGroups.Values)
            {
                group.Process();
            }
        }

        public ICollection SortedGroupCollection
        {
            get { return mGroups.Values; }
        }

        public SortedList AliasTable
        {
            get { return mAliasTable; }
            set { mAliasTable = value; }
        }
        
        public ArrayList DeepestEndDirectories
        {
            get
            {
                ArrayList aliases = new ArrayList();
                SortedList unique = new SortedList(StringComparer.OrdinalIgnoreCase);
                foreach (MyGroup group in mGroups.Values)
                {
                    foreach (MyFile file in group.Files)
                    {
                        string str = file.ShortenedDirNamePart;
                        if (str != "" && !unique.Contains(str))
                        {
                            unique.Add(str, str);
                            aliases.Add(str);
                        }
                    }
                }
                aliases.Sort();
                return aliases;
            }
        }
    }
}
